package com.learning.thread.base.thead;

/**
 * ClassName: CustomThread
 * Description: 线程的简单实现
 * 两种方式：
 * 1、继承 Thread 类
 * 2、实现 Runnable 接口
 * <p>
 * Date: 2014-6-29 8:00 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
public class CustomThread {

    public static void main(String[] args) {
        InThreadFromClass thread = new InThreadFromClass("ThreadExThread ");
        thread.start();

        Thread runnable = new Thread(new InThreadFromRunnable(), "ThreadImpRunnable");
        runnable.start();
    }

    /**
     * 继承 Thread 实现
     */
    static class InThreadFromClass extends Thread {
        public InThreadFromClass(String name) {
            super(name);
        }

        @Override
        public void run() {
            System.out.println("继承 Thread 实现线程。 线程名称为: " + Thread.currentThread().getName());
        }
    }

    /**
     * 实现 Runnable 接口实现
     */
    static class InThreadFromRunnable implements Runnable {
        @Override
        public void run() {
            System.out.println("实现 Runnable 接口实现。 线程名称为: " + Thread.currentThread().getName());
        }
    }


}
